package main

import (
	"log"

	"forum/pkg/config"
	"forum/pkg/handler"
	"forum/pkg/model/session"
	"forum/pkg/repository/mysql"
	"forum/pkg/server"
)

func init() {
	// parse configuration
	if err := config.ParseConfiguration(); err != nil {
		panic(err)
	}
}

func main() {
	// init mysql
	if err := mysql.InitDatabase(); err != nil {
		log.Fatal("initialize mysql failed")
	}

	// init session
	if err := session.InitSessionsRedisStore(); err != nil {
		log.Fatal("initialize session redis store falied: ", err)
	}

	// setup handler
	router := handler.NewHandler()

	// start server
	server.Run(router)
}
